<?php
$dirList = explode ( '/', $_SERVER ['PHP_SELF'] );
$document_root = $_SERVER ["DOCUMENT_ROOT"];
require "$document_root/$dirList[1]/conf/conf.php";

$connMng = new ConnManger ( $db_conf, $mem_conf );
$connStep = $connMng->getConn_step ();

$step_mem_list = Step_count_DAO::getList($connStep);


$mode = $_POST["mode"];
$result = "normal";
$needle = $_GET['needle'];
if ($mode == "input") {
    //按昨日步数排名
    foreach ($step_mem_list as $step_mem_record) {
        $id = $step_mem_record->getId();
        $markName = $_POST["markName$id"];
        $step_mem_record->setMarkName($markName);
        Step_count_DAO::update($step_mem_record,$connStep);
    }
    $step_mem_list = Step_count_DAO::getList($connStep);
    $result = "succ";
}

$step_mem_list = Step_count_DAO::getListByNeedle($needle,$connStep);
if (count ( $step_mem_list ) == 0) {
    $result = "notfound";
}

?>

<?php
$page_groupId = GROUP_STEP_MNG;
$page_pageId = PAGE_REMARK_NAME;
require "$document_root/$dirList[1]/mng/view/framepages/moudle_base.php";
?>


<div class="main-content">
    <div class="search-well">
        <form class="form-inline" style="margin-top: 0px;">
            用户检索 &nbsp;<input class="input-xlarge form-control"
                              placeholder="用户昵称/备注" id="4sStoreName" type="text"> &nbsp;
            <button class="btn btn-default" type="button" id="searchButton">
                <i class="fa fa-search"></i> 查找
            </button>
        </form>
    </div>

    <form method="post" action="" onSubmit="javascript:return window.confirm('确认提交吗？')" >

        <table class="table" style="word-break:break-all">
            <thead>
            <tr>

                <th>ID</th>
                <th>头像</th>
                <th width="10%">昵称</th>
                <th width="10%">备注</th>
                <th>设置备注</th>
            </tr>
            </thead>

            <tbody>
            <?php

            foreach($step_mem_list as $step_mem_record) {
                $id = $step_mem_record->getId();
                $img = $step_mem_record->getImg();
                $name = $step_mem_record->getName();
                $markName = $step_mem_record->getMarkName();
                
                echo "
                <tr>
                <td>$id</td>    
                <td><img src='$img' width='35' height='35' /></td>
                <td>$name</td>
                <td>$markName</td>
                <td><input type = 'text' name = 'markName$id' value='$markName' /></td>
                </tr>
                ";
            }
            ?>

            </tbody>
        </table>

        <input type="submit" class='btn btn-danger' value='提交'>
        <input type="hidden" name="mode" id="mode" value="input">
    </form>

    <?php
    require "$document_root/$dirList[1]/mng/view/framepages/footer.php";
    ?>
</div>
<script src="../lib/bootstrap/js/bootstrap.js"></script>

<script type="text/javascript">

    needle = "<?php echo $needle?>";
    $('#searchButton').click(function(){
        needle = $('#4sStoreName').val();
        window.location.href = "?needle="+needle;
    });
</script>

<script>

    function init() {
        var msg = "<?php echo $result ?>";
        if (msg == 'succ') {
            alert("提交成功");
        }
        if (msg == 'notfound') {
            alert("未检测到相关用户");
        }
    }

</script>
</body>
</html>
